package com.zhangmeng;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.zhangmeng.service.DataPack;
import com.zhangmeng.service.Message;
import com.zhangmeng.service.impl.DataPackImpl;
import com.zhangmeng.service.impl.MessageImpl;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @author zm
 * @date 2025/2/27 10:03
 * @version: 1.0
 */
public class DataPackTest {
    private static final Log log = LogFactory.get();
    public static void main(String[] args) {
        DataPack dp = new DataPackImpl();
        Message msg = new MessageImpl();
        msg.SetMsgId(0);
        msg.SetData("hello world\n".getBytes());
        msg.SetDataLen(msg.GetData().length);
        byte[] pack = dp.Pack(msg);
        System.out.println("pack.length:=================" + pack.length);

        // 解包
        ByteBuf byteBuf = Unpooled.wrappedBuffer(pack);
        Message unpack = dp.Unpack(byteBuf);
        log.info("==> Recv Msg: ID={}, len={}, data={}",unpack.GetMsgId(),  unpack.GetDataLen(),  new String(unpack.GetData()));

    }

}
